package com.sync;

/**
 * 所谓的线程不安全的懒汉单例写法
 * -----假设A线程执行代码1的同时，B线程执行代码2，此时，线程A可能看到instance引用的对象还没有初始化
 * Created by 峥桂 on 2017/6/6.
 */
public class UnsafeLazyInitiallization01 {
    private static UnsafeLazyInitiallization01 instance;
    private UnsafeLazyInitiallization01() {}

    public static UnsafeLazyInitiallization01 getInstance() {
        if (instance == null) {   //1:A线程执行
            instance = new UnsafeLazyInitiallization01();  //2:B线程执行
        }
        return instance;

    }
}
